﻿using System.Windows;
using MyFloridaHouse.libSvCommonUtilities;
using MyFloridaHouse.ServiceConn.DistrBldrSvcRef;
using MyFloridaHouse.libSvUtilities.Logging;
using System;

namespace MyFloridaHouse.libSvMassDataReport.Reports
{
    public partial class ACSDistrictSummary
    {
        public bool _isACSDistrictDataSummaryGenerating = false;
        public bool isACSDistrictDataSummaryGenerating
        {
            get { return _isACSDistrictDataSummaryGenerating; }
            set { if (_isACSDistrictDataSummaryGenerating != value) { _isACSDistrictDataSummaryGenerating = value; NotifyPropertyChanged("isACSDistrictDataSummaryGenerating"); } }
        }

        private void GetACSDistrictDataSummary()
        {
            try
            {
                isACSDistrictDataSummaryGenerating = true;
                ACSDistrictSummaryReportSections.Clear();
                // load up the static data
                serviceDAL.GetACSDistrictDataSummary
                        (districtSelectedIndex
                        , CompressionManager.Compress(districtCondensedList[districtSelectedIndex])
                        , Constants.ACSLayerID
                        , selectedTableIDList
                        , GetACSDistrictDataSummaryCompleted);
            }
            catch (Exception ex)
            {
                Log.HandleInternalError("GetACSDistrictDataSummary - unable to generate report: " + ex.ToString());
            }
        }

        public void GetACSDistrictDataSummaryCompleted(object sender, GetACSDistrictDataSummaryCompletedEventArgs args)
        {
            isACSDistrictDataSummaryGenerating = false;
            serviceDAL.getACSDistrictDataSummaryRequestCount--;
            reportCreatedTimeStamp = DateTime.Now.ToString();

            // error in WCF service call
            if (Log.HandleException(args.Error)) return;

            // unknown error in the service method
            if (args.Result == null)
            {
                MessageBox.Show("Error getting ACS District Summary Report  " + args.Error.Message.ToString());
            }
            else
            {
                // caught error in the service method
                if (Log.HandleServerError("GetACSDistrictSummaryCompleted", args.Result.errorMessage)) return;

                // Everything OK!

                LoadACSDistrictSummaryData(args.Result.dataSummary);



            }

        }
    }
}
